/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.report.statistics.emergencyManagement;

import com.koron.common.bean.DepartmentTreeBean;
import com.koron.common.domain.KpiStatistics;
import com.koron.common.generator.DefaultIdGenerator;
import com.koron.common.generator.GetHardwareIdFailedException;
import com.koron.common.generator.InvalidSystemClockException;
import com.koron.common.service.KpiStatisticsService;
import com.koron.common.web.Util;
import com.koron.purpose.mapper.KPITemplateMapper;
import com.koron.report.bean.StatisticsBean;
import com.koron.report.management.StatisticsManagement;
import com.koron.report.mapper.statistics.ComRateEmergPlanDrillMapper;
import com.koron.report.statistics.Contants;
import com.koron.report.statistics.StatisticsService;
import com.koron.risk.bean.CorpBean;
import com.koron.risk.service.api.CorpManagementService;
import com.koron.risk.util.BusinessCode;
import com.koron.system.domain.District;
import com.koron.system.domain.DistrictCorpRelation;
import com.koron.system.mapper.DistrictMapper;
import com.koron.system.service.api.DistrictService;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.swan.bean.MessageBean;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 应急预案演练完成率
 */
@Service("comRateEmergPlanDrillService")
@SuppressWarnings("deprecation")
public class ComRateEmergPlanDrillServiceImpl implements InitializingBean, StatisticsService {
    private final Logger logger = LoggerFactory.getLogger(ComRateEmergPlanDrillServiceImpl.class);

    // 指标code:应急预案演练实际完成总数
    private final String KPICODE_REAL = "0079";
    // 指标code:应急预案演练计划完成总数
    private final String KPICODE_PLAN = "0080";
    // 指标code:应急预案演练完成率
    private final String KPICODE_PASS = "0038";

    @Autowired
    private StatisticsManagement statisticsManagement;

    @Autowired
    private KpiStatisticsService kpiStatisticsService;

    @Autowired
    private CorpManagementService corpManagementService;

    // 获取片区信息service
    @Autowired
    private DistrictService districtService;

    @Autowired
    private Util util;

    @Override
    public void afterPropertiesSet() throws Exception {
        Set<Object> handlers = statisticsManagement.getHandlers();
        handlers.add(this);
    }

    @Override
    public void statisticsMonth(int year, int month) {

    }

    @Override
    public void statisticsQuarter(int year, int quarter) {
        SessionFactory factory = null;
        try {
            factory = new SessionFactory();
            ComRateEmergPlanDrillMapper mapper = factory.getMapper(ComRateEmergPlanDrillMapper.class);
            Calendar calendar = Calendar.getInstance();
            int month = (quarter - 1) * 3 + 1;
            calendar.set(year, month - 1, 1, 0, 0, 0);
            Date startDate = calendar.getTime();
            calendar.add(Calendar.MONTH, 3);
            Date stopDate = calendar.getTime();

            // 应急预案演练实际完成总数 指标名称
            String kpiNameReal = factory.getMapper(KPITemplateMapper.class).queryTemplateByCode(KPICODE_REAL).getName();
            // 应急预案演练计划完成总数 指标名称
            String kpiNamePlan = factory.getMapper(KPITemplateMapper.class).queryTemplateByCode(KPICODE_PLAN).getName();
            // 应急预案演练完成率 指标名称
            String kpiNamePass = factory.getMapper(KPITemplateMapper.class).queryTemplateByCode(KPICODE_PASS).getName();

            String dateValue = year + "-" + quarter;
            // 按部门
            deptTotal(mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_2, dateValue, Contants.STATISTICAL_TYPE_2, startDate, stopDate);
            // 按公司
            companyTotal(mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_2, dateValue, Contants.STATISTICAL_TYPE_3, startDate, stopDate);
            // 按片区
            areaTotal(factory, mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_2, dateValue, Contants.STATISTICAL_TYPE_4, startDate, stopDate);
            // 按集团
            blocTotal(mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_2, dateValue, Contants.STATISTICAL_TYPE_5, startDate, stopDate);
        } catch (Exception e) {
            if (factory != null) {
                factory.close(false);
            }
            logger.error(e.getMessage(),e);
            logger.error(String.format("应急预案演练完成率按季度(%o-%o季度)统计执行发生错误", year, quarter));
        }finally {
            if (factory != null) {
                factory.close();
            }
        }
    }

    @Override
    public void statisticsYear(int year) {
        SessionFactory factory = null;
        try {
            factory = new SessionFactory();
            ComRateEmergPlanDrillMapper mapper = factory.getMapper(ComRateEmergPlanDrillMapper.class);
            Calendar calendar = Calendar.getInstance();
            calendar.set(year, 0, 1, 0, 0, 0);
            Date startDate = calendar.getTime();
            calendar.add(Calendar.YEAR, 1);
            Date stopDate = calendar.getTime();

            // 应急预案演练实际完成总数 指标名称
            String kpiNameReal = factory.getMapper(KPITemplateMapper.class).queryTemplateByCode(KPICODE_REAL).getName();
            // 应急预案演练计划完成总数 指标名称
            String kpiNamePlan = factory.getMapper(KPITemplateMapper.class).queryTemplateByCode(KPICODE_PLAN).getName();
            // 应急预案演练完成率 指标名称
            String kpiNamePass = factory.getMapper(KPITemplateMapper.class).queryTemplateByCode(KPICODE_PASS).getName();

            String dateValue = String.valueOf(year);
            // 按部门
            deptTotal(mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_3, dateValue, Contants.STATISTICAL_TYPE_2, startDate, stopDate);
            // 按公司
            companyTotal(mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_3, dateValue, Contants.STATISTICAL_TYPE_3, startDate, stopDate);
            // 按片区
            areaTotal(factory, mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_3, dateValue, Contants.STATISTICAL_TYPE_4, startDate, stopDate);
            // 按集团
            blocTotal(mapper, kpiNameReal, kpiNamePlan, kpiNamePass, Contants.DATE_TYPE_3, dateValue, Contants.STATISTICAL_TYPE_5, startDate, stopDate);
        } catch (Exception e) {
            if (factory != null) {
                factory.close(false);
            }
            logger.error("应急预案演练完成率按年(" + year + ")统计执行发生错误");
        }finally {
            if (factory != null) {
                factory.close();
            }
        }
    }

    /**
     * 按部门 统计
     *
     * @param mapper
     * @param kpiNameReal     应急预案演练实际完成总数 指标名称
     * @param kpiNamePlan     应急预案演练计划完成总数 指标名称
     * @param kpiNamePass     应急预案演练完成率 指标名称
     * @param dateType        日期类型 1月，2季，3年
     * @param dateValue       日期 月：2020-01，季2020-1/2/3/4,年2020
     * @param statisticalType 统计类型：1员工，2部门，3公司，4片区，5集团
     * @param startDate
     * @param stopDate
     */
    private void deptTotal(ComRateEmergPlanDrillMapper mapper, String kpiNameReal, String kpiNamePlan, String kpiNamePass, Integer dateType, String dateValue, Integer statisticalType,
                           Date startDate, Date stopDate) throws GetHardwareIdFailedException, InvalidSystemClockException {
        // 统计查询:演练评估
        List<Map<String, String>> list1 = mapper.statisticsExerciseEvaluationTotalDept(startDate, stopDate);
        // 统计查询:应急演练
        List<Map<String, String>> list2 = mapper.statisticsEmergencyExerciseTotalDept(startDate, stopDate);
        // 处理 演练评估 数据
        List<StatisticsBean> exerciseEvaluationList = dealDataExerciseEvaluation(list1, list2);
        // 处理 应急演练 数据
        List<StatisticsBean> emergencyExerciseList = dealDataEmergencyExercise(list2);
        if (emergencyExerciseList == null || emergencyExerciseList.size() <= 0) {
            return;
        }
        //先获取当前组织架构上所有的部门
        List<DepartmentTreeBean> departmentTreeBeanList = (List<DepartmentTreeBean>) util.depttree(Contants.BLOC_CODE, 1).getData();
        if (departmentTreeBeanList == null || departmentTreeBeanList.size() <= 0) {
            return;
        }
        // 将当前获取的所有部门排除当前为水司，以及当前集团的的code
        //先排除集团
        departmentTreeBeanList = departmentTreeBeanList.stream()
                .filter(dept -> !Contants.BLOC_CODE.equals(dept.getDepartmentCode()))
                .collect(Collectors.toList());
        //获取当前标志为水司的部门（组织架构）
        List<CorpBean> corpBeanList = corpManagementService.corpBeanList();
        List<String> corpCodeList = corpBeanList.stream()
                .map(corpBean -> corpBean.getCorpCode())
                .collect(Collectors.toList());
        //再排除水司
        departmentTreeBeanList = departmentTreeBeanList.stream()
                .filter(dept -> !(corpCodeList.contains(dept.getDepartmentCode())))
                .collect(Collectors.toList());
        if (departmentTreeBeanList == null || departmentTreeBeanList.size() <= 0) {
            return;
        }
        // 演练评估
        List<StatisticsBean> exerciseEvaluations = new LinkedList<>();
        // 应急演练
        List<StatisticsBean> emergencyExercises = new LinkedList<>();
        MessageBean<?> msg;
        List<String> codes;
        List<DepartmentTreeBean> list;
        float value;
        for (DepartmentTreeBean departmentTreeBean : departmentTreeBeanList) {
            //查询该部门下所有子部门
            msg = util.depttree(departmentTreeBean.getDepartmentCode(), 1);
            codes = new LinkedList<>();
            if (msg.getData() != null) {
                list = (List<DepartmentTreeBean>) msg.getData();
                codes = list.stream().map(bean -> bean.getDepartmentCode()).collect(Collectors.toList());
            } else {
                codes.add(departmentTreeBean.getDepartmentCode());
            }
            value = 0f;
            for (StatisticsBean bean : emergencyExerciseList) {
                if (codes.contains(bean.getCode())) {
                    value += Float.valueOf(bean.getValue());
                }
            }
            if (value != 0f) {
                emergencyExercises.add(new StatisticsBean(departmentTreeBean.getDepartmentCode(), departmentTreeBean.getName(), String.valueOf(value)));
            }
            if (exerciseEvaluationList != null && exerciseEvaluationList.size() > 0) {
                value = 0f;
                for (StatisticsBean bean : exerciseEvaluationList) {
                    if (codes.contains(bean.getCode())) {
                        value += Float.valueOf(bean.getValue());
                    }
                }
                if (value != 0f) {
                    exerciseEvaluations.add(new StatisticsBean(departmentTreeBean.getDepartmentCode(), departmentTreeBean.getName(), String.valueOf(value)));
                }
            }
        }
        // 组装数据：进行统计指标添加
        assemblyData(emergencyExercises, exerciseEvaluations, kpiNameReal, kpiNamePlan, kpiNamePass, dateType, dateValue, statisticalType);
    }

    /**
     * 按公司 统计
     *
     * @param mapper
     * @param kpiNameReal     应急预案演练实际完成总数 指标名称
     * @param kpiNamePlan     应急预案演练计划完成总数 指标名称
     * @param kpiNamePass     应急预案演练完成率 指标名称
     * @param dateType        日期类型 1月，2季，3年
     * @param dateValue       日期 月：2020-01，季2020-1/2/3/4,年2020
     * @param statisticalType 统计类型：1员工，2部门，3公司，4片区，5集团
     * @param startDate
     * @param stopDate
     */
    private void companyTotal(ComRateEmergPlanDrillMapper mapper, String kpiNameReal, String kpiNamePlan, String kpiNamePass, Integer dateType, String dateValue, Integer statisticalType,
                              Date startDate, Date stopDate) throws GetHardwareIdFailedException, InvalidSystemClockException {
        // 统计查询:演练评估
        List<Map<String, String>> list1 = mapper.statisticsExerciseEvaluationTotalCompany(startDate, stopDate);
        // 统计查询:应急演练
        List<Map<String, String>> list2 = mapper.statisticsEmergencyExerciseTotalCompany(startDate, stopDate);
        // 处理 演练评估 数据
        List<StatisticsBean> exerciseEvaluationList = dealDataExerciseEvaluation(list1, list2);
        // 处理 应急演练 数据
        List<StatisticsBean> emergencyExerciseList = dealDataEmergencyExercise(list2);
        if (emergencyExerciseList != null && emergencyExerciseList.size() > 0) {
            MessageBean<CorpBean> corpBean;
            for (StatisticsBean statisticsBean : emergencyExerciseList) {
                // 获取水司名称
                corpBean = corpManagementService.getOne(statisticsBean.getCode());
                if (corpBean.getCode() == BusinessCode.MESSAGE_CODE_SUCCESS) {
                    statisticsBean.setCodeName(corpBean.getData().getCorpName());
                } else {
                    statisticsBean.setCodeName("");
                }
            }
        }
        // 组装数据：进行统计指标添加
        assemblyData(emergencyExerciseList, exerciseEvaluationList, kpiNameReal, kpiNamePlan, kpiNamePass, dateType, dateValue, statisticalType);
    }

    /**
     * 按片区 统计
     *
     * @param factory
     * @param mapper
     * @param kpiNameReal     应急预案演练实际完成总数 指标名称
     * @param kpiNamePlan     应急预案演练计划完成总数 指标名称
     * @param kpiNamePass     应急预案演练完成率 指标名称
     * @param dateType        日期类型 1月，2季，3年
     * @param dateValue       日期 月：2020-01，季2020-1/2/3/4,年2020
     * @param statisticalType 统计类型：1员工，2部门，3公司，4片区，5集团
     * @param startDate
     * @param stopDate
     * @throws GetHardwareIdFailedException
     * @throws InvalidSystemClockException
     */
    private void areaTotal(SessionFactory factory, ComRateEmergPlanDrillMapper mapper, String kpiNameReal, String kpiNamePlan, String kpiNamePass, Integer dateType,
                           String dateValue, Integer statisticalType, Date startDate, Date stopDate) throws GetHardwareIdFailedException, InvalidSystemClockException {
        // 统计查询:演练评估
        List<Map<String, String>> list1 = mapper.statisticsExerciseEvaluationTotalCompany(startDate, stopDate);
        // 统计查询:应急演练
        List<Map<String, String>> list2 = mapper.statisticsEmergencyExerciseTotalCompany(startDate, stopDate);
        // 处理 演练评估 数据
        List<StatisticsBean> exerciseEvaluationList = dealDataExerciseEvaluation(list1, list2);
        // 处理 应急演练 数据
        List<StatisticsBean> emergencyExerciseList = dealDataEmergencyExercise(list2);
        List<District> districtList = factory.getMapper(DistrictMapper.class).queryAllDistrict(null, null);
        if (districtList != null && districtList.size() > 0) {
            // 演练评估
            List<StatisticsBean> exerciseEvaluations = new LinkedList<>();
            // 应急演练
            List<StatisticsBean> emergencyExercises = new LinkedList<>();
            for (District district : districtList) {
                // 根据片区code，获取片区下所有公司信息
                List<DistrictCorpRelation> districtCorpRelationList = districtService.queryAssociatedCorp(district.getCode());
                float valueExerciseEvaluation = 0f;
                float valueEmergencyExercises = 0f;
                if (districtCorpRelationList != null && districtCorpRelationList.size() > 0) {
                    for (DistrictCorpRelation districtCorpRelation : districtCorpRelationList) {
                        // 根据code 获取value值
                        valueExerciseEvaluation += getValueByCode(exerciseEvaluationList, districtCorpRelation.getCorpCode());
                        // 根据code 获取value值
                        valueEmergencyExercises += getValueByCode(emergencyExerciseList, districtCorpRelation.getCorpCode());
                    }
                }
                exerciseEvaluations.add(new StatisticsBean(district.getCode(), district.getName(), Float.valueOf(valueExerciseEvaluation).toString()));
                emergencyExercises.add(new StatisticsBean(district.getCode(), district.getName(), Float.valueOf(valueEmergencyExercises).toString()));
            }
            // 组装数据：进行统计指标添加
            assemblyData(emergencyExercises, exerciseEvaluations, kpiNameReal, kpiNamePlan, kpiNamePass, dateType, dateValue, statisticalType);
        }
    }

    /**
     * 按集团 统计
     *
     * @param mapper
     * @param kpiNameReal     应急预案演练实际完成总数 指标名称
     * @param kpiNamePlan     应急预案演练计划完成总数 指标名称
     * @param kpiNamePass     应急预案演练完成率 指标名称
     * @param dateType        日期类型 1月，2季，3年
     * @param dateValue       日期 月：2020-01，季2020-1/2/3/4,年2020
     * @param statisticalType 统计类型：1员工，2部门，3公司，4片区，5集团
     * @param startDate
     * @param stopDate
     * @throws GetHardwareIdFailedException
     * @throws InvalidSystemClockException
     */
    private void blocTotal(ComRateEmergPlanDrillMapper mapper, String kpiNameReal, String kpiNamePlan, String kpiNamePass, Integer dateType, String dateValue, Integer statisticalType,
                           Date startDate, Date stopDate) throws GetHardwareIdFailedException, InvalidSystemClockException {
        // 统计查询:演练评估
        List<Map<String, String>> list1 = mapper.statisticsExerciseEvaluationTotalCompany(startDate, stopDate);
        // 统计查询:应急演练
        List<Map<String, String>> list2 = mapper.statisticsEmergencyExerciseTotalCompany(startDate, stopDate);
        // 处理 演练评估 数据
        List<StatisticsBean> exerciseEvalList = dealDataExerciseEvaluation(list1, list2);
        // 处理 应急演练 数据
        List<StatisticsBean> emergencyExerList = dealDataEmergencyExercise(list2);
        // 统计查询:演练评估
        Float exerciseEvaluationValue = 0f;
        if (exerciseEvalList != null && exerciseEvalList.size() > 0) {
            for (StatisticsBean bean : exerciseEvalList) {
                exerciseEvaluationValue += Float.valueOf(bean.getValue());
            }
        }
        List<StatisticsBean> exerciseEvaluationList = new ArrayList<>();
        exerciseEvaluationList.add(new StatisticsBean(Contants.BLOC_CODE, Contants.BLOC_NAME, String.valueOf(exerciseEvaluationValue)));
        // 统计查询:应急演练
        Float emergencyExerciseValue = 0f;
        if (emergencyExerList != null && emergencyExerList.size() > 0) {
            for (StatisticsBean bean : emergencyExerList) {
                exerciseEvaluationValue += Float.valueOf(bean.getValue());
            }
        }
        List<StatisticsBean> emergencyExerciseList = new ArrayList<>();
        emergencyExerciseList.add(new StatisticsBean(Contants.BLOC_CODE, Contants.BLOC_NAME, String.valueOf(emergencyExerciseValue)));
        // 组装数据：进行统计指标添加
        assemblyData(emergencyExerciseList, exerciseEvaluationList, kpiNameReal, kpiNamePlan, kpiNamePass, dateType, dateValue, statisticalType);
    }

    /**
     * 组装数据：进行统计指标添加
     *
     * @param emergencyExerciseList  应急演练list
     * @param exerciseEvaluationList 演练评估list
     * @param kpiNameReal            应急预案演练实际完成总数 指标名称
     * @param kpiNamePlan            应急预案演练计划完成总数 指标名称
     * @param kpiNamePass            应急预案演练完成率 指标名称
     * @param dateType               日期类型 1月，2季，3年
     * @param dateValue              日期 月：2020-01，季2020-1/2/3/4,年2020
     * @param statisticalType        统计类型：1员工，2部门，3公司，4片区，5集团
     * @throws GetHardwareIdFailedException
     * @throws InvalidSystemClockException
     */
    private void assemblyData(List<StatisticsBean> emergencyExerciseList, List<StatisticsBean> exerciseEvaluationList,
                              String kpiNameReal, String kpiNamePlan, String kpiNamePass, Integer dateType, String dateValue, Integer statisticalType) throws GetHardwareIdFailedException, InvalidSystemClockException {
        // 统计查询:应急预案演练完成率
        if (emergencyExerciseList != null && emergencyExerciseList.size() > 0) {
            List<KpiStatistics> insertList = new LinkedList<>();
            for (StatisticsBean statisticsBean : emergencyExerciseList) {
                float value = 0f;
                // 演练评估
                if (exerciseEvaluationList != null && exerciseEvaluationList.size() > 0) {
                    for (StatisticsBean qualifiedTotal : exerciseEvaluationList) {
                        if (statisticsBean.getCode().equals(qualifiedTotal.getCode())) {
                            value = Float.valueOf(qualifiedTotal.getValue());
                            break;
                        }
                    }
                }
                insertList.add(new KpiStatistics(
                        DefaultIdGenerator.getInstance().generateLongId(),
                        kpiNameReal,
                        KPICODE_REAL,
                        value,
                        dateType,
                        dateValue,
                        statisticalType,
                        statisticsBean.getCode(),
                        statisticsBean.getCodeName(),
                        new Date()
                ));
                // 应急演练
                insertList.add(new KpiStatistics(
                        DefaultIdGenerator.getInstance().generateLongId(),
                        kpiNamePlan,
                        KPICODE_PLAN,
                        Float.valueOf(statisticsBean.getValue()),
                        dateType,
                        dateValue,
                        statisticalType,
                        statisticsBean.getCode(),
                        statisticsBean.getCodeName(),
                        new Date()
                ));
                // 应急预案演练完成率
                float percentPass = Float.valueOf(statisticsBean.getValue());
                if (percentPass != 0f) {
                    percentPass = value / percentPass;
                }
                insertList.add(new KpiStatistics(
                        DefaultIdGenerator.getInstance().generateLongId(),
                        kpiNamePass,
                        KPICODE_PASS,
                        percentPass,
                        dateType,
                        dateValue,
                        statisticalType,
                        statisticsBean.getCode(),
                        statisticsBean.getCodeName(),
                        new Date()
                ));
                kpiStatisticsService.delete(KPICODE_REAL, dateValue, statisticsBean.getCode());
                kpiStatisticsService.delete(KPICODE_PLAN, dateValue, statisticsBean.getCode());
                kpiStatisticsService.delete(KPICODE_PASS, dateValue, statisticsBean.getCode());
            }
            kpiStatisticsService.batchInsert(insertList);
        }
    }

    /**
     * 根据code 获取value值
     *
     * @param list
     * @param code
     */
    private float getValueByCode(List<StatisticsBean> list, String code) {
        if (list != null && list.size() > 0) {
            for (StatisticsBean statisticsBean : list) {
                if (statisticsBean.getCode().equals(code)) {
                    return Float.valueOf(statisticsBean.getValue());
                }
            }
        }
        return 0f;
    }

    /**
     * 处理 演练评估 数据
     *
     * @param exerciseEvaluationList 演练评估
     * @param emergencyExerciseList  应急演练
     * @return
     */
    private List<StatisticsBean> dealDataExerciseEvaluation(List<Map<String, String>> exerciseEvaluationList, List<Map<String, String>> emergencyExerciseList) {
        List<StatisticsBean> exerciseEvaluationGather = new LinkedList<>();
        if (emergencyExerciseList != null && emergencyExerciseList.size() > 0
                && exerciseEvaluationList != null && exerciseEvaluationList.size() > 0) {
            List<String> codes = emergencyExerciseList.stream()
                    .map(emergencyExercise -> emergencyExercise.get("code")).collect(Collectors.toList());
            // 演练评估
            exerciseEvaluationList.stream().forEach(exerciseEvaluation -> {
                if (codes.contains(exerciseEvaluation.get("code"))) {
                    if (exerciseEvaluationGather.stream().map(m -> m.getCode()).collect(Collectors.toList()).contains(exerciseEvaluation.get("code"))) {
                        exerciseEvaluationGather.stream().forEach(statisticsBean -> {
                            if (statisticsBean.getCode().equals(exerciseEvaluation.get("code"))) {
                                statisticsBean.setValue((Float.valueOf(statisticsBean.getValue()) + 1f) + "");
                            }
                        });
                    } else {
                        exerciseEvaluationGather.add(new StatisticsBean(exerciseEvaluation.get("code"), exerciseEvaluation.get("codeName"), "1"));
                    }
                }
            });
        }
        return exerciseEvaluationGather;
    }

    /**
     * 处理 应急演练 数据
     *
     * @param emergencyExerciseList 应急演练
     * @return
     */
    private List<StatisticsBean> dealDataEmergencyExercise(List<Map<String, String>> emergencyExerciseList) {
        List<StatisticsBean> emergencyExerciseGather = new LinkedList<>();
        if (emergencyExerciseList != null && emergencyExerciseList.size() > 0) {
            // 应急演练
            emergencyExerciseList.stream().forEach(emergencyExercise -> {
                if (emergencyExerciseGather.stream().map(m -> m.getCode()).collect(Collectors.toList()).contains(emergencyExercise.get("code"))) {
                    emergencyExerciseGather.stream().forEach(statisticsBean -> {
                        if (statisticsBean.getCode().equals(emergencyExercise.get("code"))) {
                            statisticsBean.setValue((Float.valueOf(statisticsBean.getValue()) + 1f) + "");
                        }
                    });
                } else {
                    emergencyExerciseGather.add(new StatisticsBean(emergencyExercise.get("code"), emergencyExercise.get("codeName"), "1"));
                }
            });
        }
        return emergencyExerciseGather;
    }
}
